package com.nowcoder.community.service;

import com.nowcoder.community.dao.AlphaDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Service
//@Scope("prototype")
public class AlphaService {

    private static final Logger logger = LoggerFactory.getLogger(AlphaService.class);
    @Autowired
    private AlphaDao alphaDao;

    public AlphaService() {
//        System.out.println("实例化AlphaService");
    }

    @PostConstruct
    public void init() {
//        System.out.println("初始化AlphaService");
    }

    @PreDestroy
    public void destroy() {
//        System.out.println("销毁AlphaService");
    }

    public String find() {
        return alphaDao.select();
    }


    @Async //使该方法可以在多线程环境下，被异步调用
    public void execute1(){
        logger.debug("execute1");
    }

    //只要有程序运行，scheduling 定时任务就会进行自动的调用
    //initialDelay 就是程序启动之后，我们 10 秒止之后才会被调用
    //fixedDelay 就是第一次调用之后，每隔一秒，自动调用一次，直到程序执行结束
    //@Scheduled(initialDelay = 10000, fixedDelay = 1000)
    public void execute2(){
        logger.debug("execute2");
    }

}
